package com.woniuxy.oldobject.controller;

import com.github.pagehelper.PageHelper;
import com.woniuxy.oldobject.dto.UmbettenDto;
import com.woniuxy.oldobject.entity.ResponseEntity;
import com.woniuxy.oldobject.entity.Umbetten;
import com.woniuxy.oldobject.service.UmbettenService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @Description: 床位申请表Controller接口
 * @Title: UmbettenController
 * @Package com.woniuxy.oldobject.controller
 * @Author: LSL
 * @CreateTime: 2022/7/30 17:15
 */
@RestController
@RequestMapping("/umbetten")
public class UmbettenController {
    @Autowired
    UmbettenService umbettenService;

    /**
     * 条件查询床位申请表数据并分页
     *
     * @param umbetten
     * @return
     */
    @PostMapping("/queryAllByLimit")
    public ResponseEntity queryAllByLimit(@RequestBody UmbettenDto umbetten) {
        PageHelper.startPage(umbetten.getPageSize(), umbetten.getPageNum());
        List<Umbetten> umbettens = umbettenService.queryAllByLimit(umbetten);
        if (umbettens.size() != 0) {
            return new ResponseEntity(umbettens);
        }
        return ResponseEntity.ERROR;
    }

    /**
     * 新增床位盛情数据
     *
     * @param umbettenDto
     * @return
     */
    @PostMapping("/insert")
    public ResponseEntity insert(@RequestBody UmbettenDto umbettenDto) {
        int insert = umbettenService.insert(umbettenDto);
        if (insert != 0) {
            return ResponseEntity.SUCCESS;
        }
        return ResponseEntity.ERROR;
    }

    /**
     * 修改床位数据
     *
     * @param umbettenDto
     * @return
     */
    @PostMapping("/update")
    public ResponseEntity update(@RequestBody UmbettenDto umbettenDto) {
        int update = umbettenService.update(umbettenDto);
        if (update != 0) {
            return ResponseEntity.SUCCESS;
        }
        return ResponseEntity.ERROR;
    }
}
